/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chromafinal;

/**
 *
 * @author Benjamin
 */

//A wall.
//nuff said
import java.awt.Color;
import java.awt.Graphics;

public class Wall extends LevelObject{
    int x1,y1,x2,y2;
    int width;
    boolean horz;

    public Wall(int x11, int y11, int x22, int y22, int width)
    {
        this.x1 = Math.min(x11,x22);
        this.y1 = Math.min(y11,y22);
        this.x2 = Math.max(x11,x22);
        this.y2 = Math.max(y11,y22);
        this.width = width;
        horz = (y11 == y22);
        if (horz)
        {
            leftx = x1;
            rightx = x2;
        }
        else
        {
            leftx = x1-width;
            rightx = x1+width;
        }
        otype = WALL;
    }

    public void pushPlayer(Player p)
    {
        int i = Game.screenloc;

        int[] crds = p.getRelCoords();

        if (horz)
        {
            if(crds[1] < y1 + width + 8 && crds[1] > y1-width-8)
                if(crds[0] > x1-9 && crds[0] < x2 + 9)
                    if (crds[0] > x1-5 && crds[0] < x2 + 5)
                    {
                        if (crds[1] > y1)
                        {
                            vertBouncePlayer(p,y1+width+10);
                            return;
                        }
                        else
                        {
                            vertBouncePlayer(p,y1-width-10);
                            return;
                        }
                    }
                    else
                    {
                        if (crds[0] < x1)
                        {
                            horzBouncePlayer(p,x1-10-i);
                            return;
                        }
                        else
                        {
                            horzBouncePlayer(p,x2+10-i);
                            return;
                        }
                    }
        }
        else
        {
            if(crds[0] < x1 + width + 8 && crds[0] > x1-width-8)
                if(crds[1] > y1-9 && crds[1] < y2 + 9)
                    if (crds[1] > y1-5 && crds[1] < y2 + 5)
                    {
                        if (crds[0] > x1)
                        {
                            horzBouncePlayer(p,x1+width+10-i);
                            return;
                        }
                        else
                        {
                            horzBouncePlayer(p,x1-width-10-i);
                            return;
                        }
                    }
                    else
                    {
                        if (crds[1] < y1)
                        {
                            vertBouncePlayer(p,y1-10);
                            return;
                        }
                        else
                        {
                            vertBouncePlayer(p,y2+10);
                            return;
                        }
                    }

        }

        
    }

    public void vertBouncePlayer(Player p, int l)
    {
        if (!p.invincible())
        {
            p.yl = l;
            p.yv = p.yv * -0.4;
        }
    }

    public void horzBouncePlayer(Player p, int l)
    {
        if (!p.invincible())
        {
            if (l < 11)
            {
                p.die();
                return;
            }
            p.xl = l;
            p.xv = p.xv * -0.4;
        }
    }

    public void draw(Graphics g)
    {
        int i = Game.screenloc;

        g.setColor(Color.gray);
        if (horz)
            g.fillRect(x1-i,y1-width,x2-x1, width * 2);
        else
            g.fillRect(x1-width-i, y1, width*2, y2-y1);
        
    }

    public String makeText()
    {
            String oput = otype +"\t"+ x1 + "\t" + y1 + "\t" + x2 + "\t"
                    + y2 + "\t" + width + "\n";
            return oput;
    }

}
